<?php


header("Content-Type: text/html; charset=utf-8");
require_once("conn.inc");
date_default_timezone_set("PRC");



$mysql = new Mysql();

$bg_people_name = $_POST['bg_people_name'];
$bg_title = $_POST['title'];
$bg_note = $_POST['note'];

$sql = sprintf ("SELECT * FROM %s WHERE name = \"%s\"","people",$bg_people_name);


$bg_people = $mysql->select($sql);

$ret = array();
if ((!$bg_people) or count ($bg_people) == 0) {
	$ret["statu"] = "error";
	$ret["error_info"] = "不能查到报告人信息".$sql;
	echo json_encode($ret);
	return;
}

$bg_people_id = $bg_people[0]["id"];
$cur_time = date("Y-m-d");
$statu = "running";

$strsql = sprintf ('Insert into bg(title,node,start_date,statu,bg_people_id) values ("%s","%s","%s","%s",%d)',$bg_title,$bg_note,$cur_time,$statu,$bg_people_id);
if ($mysql->edit($strsql)) {
	$ret["statu"] = "success";
	$ret["error_info"] = $strsql;
	//mysql_insert_id()只返回当前连接的AUTO_INCREMENT 
	$bg_id =  mysql_insert_id();
	$query = sprintf ("select bg.id as id, bg.title as title ,people.name as bg_people_name, bg.start_date as start_date,bg.statu as statu ,bg.node as node from bg,people where bg.id = %d and bg.bg_people_id = people.id",$bg_id);
	$result = $mysql->select($query);
	$ret["result"] = $result;
	$ret["error_info"] = $ret["error_info"].$query;
} else {
	$ret["statu"] = "error";
	$ret["error_info"] = "插入失败".$strsql;
}

echo json_encode($ret);
?>